﻿// Copyright (c)  YISH. All rights reserved.
// Licensed under the MIT License, See License.txt in the project root for license information.

using System.Linq;
using NSQL.Sharpen;

namespace NSQL.Expressions
{
    /// <summary>
    /// values can be constant Value or subquery
    /// </summary>
    public class InExpression : BaseExpression, IInExpression
    {
        public IExpression Left { get; set; }
        public IExpressions Elements { get; set; }

        public InExpression(IExpression expression, IExpressions inElements)
        {
            Left = expression;
            Elements = inElements;
        }

        public override T Accept<T>(IExpressionVisitor<T> visitor) => visitor.Visit(this);
        public override void Accept(IExpressionVisitor visitor) => visitor.Visit(this);
        public override bool IsValid => Left.IsValid && Elements.Any(o => o.IsValid);
        protected override IExpression DeepCopy()
        {
            return new InExpression(Left.DeepClone(), Elements.DeepClone());
        }
    }
}